package com.suntront.module_bluetooth.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.mtjsoft.www.kotlinmvputils.imp.AdapterItemClickListener;
import com.suntront.module_bluetooth.R;
import com.suntront.module_bluetooth.model.BlueToothModel;

import java.util.List;

/**
 * @author mtj
 * @Package com.mtjsoft.mvvmtest.adapter
 * @date 2020-05-21 13:28:46
 */

public class BlueToothAdapter extends BaseMultiItemQuickAdapter<BlueToothModel, BaseViewHolder> {

    private Context context;
    private AdapterItemClickListener adapterItemClickListener;

    public BlueToothAdapter(Context context, List<BlueToothModel> list, AdapterItemClickListener adapterItemClickListener) {
        super(list);
        this.context = context;
        this.adapterItemClickListener = adapterItemClickListener;
        // 绑定 layout 对应的 type，实现列表多布局
        addItemType(BlueToothModel.TITLE_TYPE, R.layout.item_bluetooth_title);
        addItemType(BlueToothModel.CONTENT_TYPE, R.layout.item_bluetooth);
    }

    @Override
    protected void convert(BaseViewHolder holder, BlueToothModel model) {
        int position = holder.getLayoutPosition();
        // 根据返回的 type 分别设置数据
        switch (holder.getItemViewType()) {
            case BlueToothModel.TITLE_TYPE:
                holder.setText(R.id.tv_type_name, model.getName());
                break;
            case BlueToothModel.CONTENT_TYPE:
                holder.setText(R.id.tv_name, model.getName());
                holder.setText(R.id.tv_address, model.getAddress());
                holder.getView(R.id.ll_item).setOnClickListener(v -> {
                    adapterItemClickListener.onItemClick(position, v);
                });
                break;
        }
    }
}